package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import org.owasp.esapi.ESAPI;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * @author 123
 *
 */
public class EmailSendRequest extends Request {
	
	/**
	 * 发送方
	 */
	private String sender;
	/**
	 * 接收方
	 */
	private String receiver;
	/**
	 * 发送内容
	 */
	private String content;
	/**
	 * 邮件主题
	 */
	private String subject;
	/**
	 * 图片
	 */
	private String imgPath;
	/**
	 * 抄送人
	 */
	private String ccReceiver;
	/**
	 * 密送人
	 */
	private String bccReceiver;
	/**
	 * 模板名称
	 */
	private String templateName;
	/**
	 * 邮件附件
	 */
	private String attachment;
	
	public String getAttachment() {
		return attachment;
	}

	public void setAttachment(String attachment) {
		this.attachment = attachment;
	}

	public String getCcReceiver() {
		return ccReceiver;
	}

	public void setCcReceiver(String ccReceiver) {
		this.ccReceiver = ccReceiver;
	}

	public String getBccReceiver() {
		return bccReceiver;
	}

	public void setBccReceiver(String bccReceiver) {
		this.bccReceiver = bccReceiver;
	}

	public String getImgPath() {
		return imgPath;
	}

	public void setImgPath(String imgPath) {
		this.imgPath = imgPath;
	}

	public String getTemplateName() {
		return templateName;
	}

	public void setTemplateName(String templateName) {
		this.templateName = templateName;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}


	
	/** */
	public EmailSendRequest() {
	}
	
	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
	
		this.sender = requestInfo.getParameter(ApiUrlParamEnum.sender.getParamName());
		this.receiver = requestInfo.getParameter(ApiUrlParamEnum.receiver.getParamName());
		this.content = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.content.getParamName()));
		this.subject = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.subject.getParamName()));
		this.templateName = StringUtil.fixHtml(requestInfo.getParameter(ApiUrlParamEnum.templateName.getParamName()));

		if ( StringUtil.isEmpty(sender) ) {
			throw new RequestIllegalException("error sender: " + sender);
		}
		if ( StringUtil.isEmpty(receiver) ) {
			throw new RequestIllegalException("error receiver: " + receiver);
		}
		if ( StringUtil.isEmpty(content) ) {
			throw new RequestIllegalException("error content: " + content);
		}
		if ( StringUtil.isEmpty(subject) ) {
			throw new RequestIllegalException("error subject: " + subject);
		}
		if ( StringUtil.isEmpty(templateName) ) {
			throw new RequestIllegalException("error templateName: " + templateName);
		}
	}
	
	
}
